package com.cxy.instarsystem.vo;

import com.alibaba.fastjson.JSONObject;
import com.cxy.instarsystem.constants.ResponseStatus;
import com.cxy.instarsystem.util.DesUtils;
import com.cxy.instarsystem.util.MD5Utils;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class EncryptResponse<T> extends BaseResponse {
    private Integer code;
    private String encryptData;
    private String signature;
    private String message;

    public static <T> EncryptResponse<T> success(T data){
        EncryptResponse<T> encryptResponse = new EncryptResponse<>();
        String dataJson = JSONObject.toJSONString(data);
        String encryptData = DesUtils.encode(dataJson);
        encryptResponse.setEncryptData(encryptData);
        encryptResponse.setCode(ResponseStatus.SUCCESS.getCode());
        encryptResponse.setSignature(MD5Utils.code(encryptData));
        return encryptResponse;
    }
    public static <T> EncryptResponse<T> error(T data, String message){
        EncryptResponse<T> encryptResponse = new EncryptResponse<>();
        String dataJson = JSONObject.toJSONString(data);
        String encryptData = DesUtils.encode(dataJson);
        encryptResponse.setEncryptData(encryptData);
        encryptResponse.setCode(ResponseStatus.ERROR.getCode());
        encryptResponse.setSignature(MD5Utils.code(encryptData));
        encryptResponse.setMessage(message);
        return encryptResponse;
    }
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getEncryptData() {
        return encryptData;
    }
    public void setEncryptData(String encryptData) {
        this.encryptData = encryptData;
    }

    public String getSignature() {
        return signature;
    }
    public void setSignature(String signature) {
        this.signature = signature;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "EncryptResponse{" +
                "code=" + code +
                ", encryptData='" + encryptData + '\'' +
                ", signature='" + signature + '\'' +
                ", message='" + message + '\'' +
                '}';
    }
}
